import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

export type fileResult = {
  success: boolean;
  msg: string;
  data: any;
};

/** 获取项目名 */
export const getProjectList = () => {
  return http.request<fileResult>("post", baseUrlApi("file/getProjectList"));
};

/** 获取项目jmx文件 */
export const getJmxName = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getJmxName"), {
    data
  });
};

/** 获取项目jmx文件详细信息 */
export const getJmxInfo = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getJmxInfo"), {
    data
  });
};

export const getParamsFilesInfo = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/getParamsFilesInfo"),
    {
      data
    }
  );
};

/** 获取项目jmx文件 */
export const delJmx = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/delJmx"), {
    data
  });
};

/* 获取邮件配置 */
export const getEmailConfig = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getEmailConfig"), {
    data
  });
};

/** 保存邮件配置 */
export const saveEmailConfig = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/saveEmailConfig"), {
    data
  });
};

/* 获取Yaml文件 */
export const getYamlConfig = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getYamlConfig"), {
    data
  });
};
/* 获取Yaml-Runtime */
export const getYamlRuntime = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/getYamlRuntime"), {
    data
  });
};
/* 获取Yaml-Execution */
export const getYamlExecution = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getYamlExecution"), {
    data
  });
};

/* 保存Yaml文件 */
export const saveYamlConfig = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/saveYamlConfig"), {
    data
  });
};

/** 快速生成yaml */
// export const quickAddYamlConfig = (data?: object) => {
//   return http.request<fileResult>(
//     "post",
//     baseUrlApi("file/quickAddYamlConfig"),
//     {
//       data
//     }
//   );
// };

/** 下载Jmeter插件 */
export const downloadJmeterPlugins = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("file/downloadJmeterPlugins"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

export const downloadRecordingPlugins = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("downloadRecordingPlugins"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};
/** 下载用户手册 */
export const downloadUserHelpFile = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("file/downloadUserHelpFile"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};
/** 快速生成项目 */
export const creatProject = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/creatProject"), {
    data
  });
};

/** 删除项目 */
export const delProject = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/delProject"), {
    data
  });
};

/** 执行测试 */
export const runProject = (data?: object, axiosConfig?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/runProject"),
    {
      data
    },
    axiosConfig
  );
};

/** 查看报告目录 */
export const generateNewYaml = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/generateNewYaml"), {
    data
  });
};

/** 检测测试 */
export const checkRun = (data?: object, axiosConfig?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/checkRun"),
    {
      data
    },
    axiosConfig
  );
};

/** 停止测试 */
export const stopProject = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/stopProject"), {
    data
  });
};

/** 查看报告 */
export const getReport = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getReport"), {
    data
  });
};

/** 查看报告目录 */
export const getReportDir = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getReportDir"), {
    data
  });
};

/** 检验脚本结构 */
export const checkJmxFile = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/checkJmxFile"), {
    data
  });
};

/* 下载脚本文件 */
export const downloadJmxFile = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("file/downloadJmxFile"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

/* 下载所有脚本文件 */
export const downloadAllFile = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("file/downloadAllFile"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

/** 是否开启资源监控 */
export const isOpenMonitor = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/IsOpenMonitor"), {
    data
  });
};

/** 获取资源监控状态 */
export const getMonitorStatus = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/getMonitorStatus"),
    {
      data
    }
  );
};

/** 获取测试机信息 */
export const getMachineInfo = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getMachineInfo"), {
    data
  });
};

/** 查询启用状态的测试机 */
export const getActiveMachines = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/getActiveMachines"),
    {
      data
    }
  );
};
// export const getActiveMachines = () => {
//   return http.request<fileResult>("get", baseUrlApi("/file/getActiveMachines"));
// };
// export const getActiveMachines = (params: {
//   status?: string;
//   page?: number;
//   size?: number;
// }) => {
//   // 将参数传递给http请求
//   return http.request<fileResult>(
//     "get",
//     baseUrlApi("/file/getActiveMachines"),
//     { params }
//   );
// };

/** 测试机ssh校验 */
export const testingConnection = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/testingConnection"),
    {
      data
    }
  );
};

/** 测试环境检查 */
export const checkEnvironment = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/checkEnvironment"),
    {
      data
    }
  );
};

/** 启动jmeter-server */
export const startJmeter = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/startJmeter"), {
    data
  });
};

/** 检查是否启动jmeter-server */
export const checkJmeterIsOpen = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/checkJmeterIsOpen"),
    {
      data
    }
  );
};

/** 新增测试机 */
export const addTestingMachine = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/addTestingMachine"),
    {
      data
    }
  );
};

/** 编辑测试机 */
export const editTestingMachine = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/editTestingMachine"),
    {
      data
    }
  );
};

/** 删除测试机 */
export const deleteTestingMachine = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/deleteTestingMachine"),
    {
      data
    }
  );
};

/** 测试机禁用/启用 */
export const machineIsEnable = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/machineIsEnable"), {
    data
  });
};

/** 查询YAML文件中distributed的值 */
export const getDistributedValues = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/getDistributedValues"),
    {
      data
    }
  );
};

/** 修改YAML中distributed的值 */
export const updateDistributedValue = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/updateDistributedValue"),
    {
      data
    }
  );
};

/** 快速修改执行策略 */
export const overallUpdateYamlConfig = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("/file/overallUpdateYamlConfig"),
    {
      data
    }
  );
};

/** 添加测试场景 */
export const addScenario = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/addScenario"), {
    data
  });
};

/** 删除测试场景 */
export const deleteScenario = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/deleteScenario"), {
    data
  });
};

/* 编辑测试场景 */
export const updateScenario = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/updateScenario"), {
    data
  });
};

/* 编辑测试场景 */
export const updateTime = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/updateTime"), {
    data
  });
};

/* 下载报告 */
export const downloadReport = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("file/downloadReport"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

/* 获取项目创建者 */
export const getCreater = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/getCreater"), {
    data
  });
};

/* 获取用户IP */
export const getUserIP = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/getUserIP"), {
    data
  });
};

/* 获取用户IP */
export const getExecutor = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("/file/getExecutor"), {
    data
  });
};

/* 查询所有项目 */
export const getProjectStatistics = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getProjectStatistics"), {
    data
  });
};

/* 查询项目详细信息 */
export const getProjectDetailInfo = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getProjectDetailInfo"), {
    data
  });
};

export const getProjectInfo = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getProjectInfo"), {
    data
  });
};

export const bindSlaveIP = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/bindSlaveIP"), {
    data
  });
};

export const getBindSlaveIp = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("file/getBindSlaveIp"), {
    data
  });
};
export const getUseableSlaveIp = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getUseableSlaveIp"), {
    data
  });
};

export const getJmeterLog = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getJmeterLog"), {
    data
  });
};

export const getTaurusLog = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getTaurusLog"), {
    data
  });
};

/* 下载日志文件 */
export const downloadJmeterLog = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("downloadJmeterLog"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};
export const downloadTaurusLog = (data?: object) => {
  return http.request<Blob>(
    "post",
    baseUrlApi("downloadTaurusLog"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

export const generateBuildYaml = (data?: object) => {
  return http.request<fileResult>(
    "post",
    baseUrlApi("file/generateBuildYaml"),
    {
      data
    }
  );
};

export const createTask = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("createTask"), {
    data
  });
};

export const getPlanlist = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("getPlanlist"), {
    data
  });
};
export const modifyTaskTime = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("modifyTaskTime"), {
    data
  });
};

export const cancelTask = (data?: object) => {
  return http.request<fileResult>("post", baseUrlApi("cancelTask"), {
    data
  });
};
